clear

*This do file prepares EVRR for merge with Leblang's micro-level data
*Last updated: May 16, 2022

*Insert your root folder location below
cd  "FOLDER YOUR LOCATION HERE

use "EVRR_Dataset.dta"

sort stateid year

*Cutnote: remove folder root in final version
save "evrr_merge.dta", replace


use "ExtraDatasets\micro_data.dta"

*To facilitate the merge, we need to add stateid to the microdata. 
*It's best to use "ifs", as this is the only country-specific id consistent in Leblang's dataset.

gen str3 stateid="xxx"				
replace stateid = "MLI" if ifs==678
replace stateid = "SAU" if ifs==456
replace stateid = "" if ifs==314
replace stateid = "" if ifs==938
replace stateid = "WSM" if ifs==862
replace stateid = "SEN" if ifs==722
replace stateid = "GUA" if ifs==258
replace stateid = "MEX" if ifs==273
replace stateid = "" if ifs==479
replace stateid = "STP" if ifs==716
replace stateid = "VEN" if ifs==299
replace stateid = "TAJ" if ifs==923
replace stateid = "CZE" if ifs==934
replace stateid = "BOS" if ifs==963
replace stateid = "CZR" if ifs==935
replace stateid = "NIG" if ifs==694
replace stateid = "MAD" if ifs==556
replace stateid = "SWA" if ifs==734
replace stateid = "OMA" if ifs==449
replace stateid = "KUW" if ifs==443
replace stateid = "MAG" if ifs==674
replace stateid = "BLR" if ifs==913
replace stateid = "NIR" if ifs==692
replace stateid = "" if ifs==537
replace stateid = "EST" if ifs==939
replace stateid = "PAR" if ifs==288
replace stateid = "" if ifs==859
replace stateid = "BEN" if ifs==638
replace stateid = "ROK" if ifs==542
replace stateid = "RWA" if ifs==714
replace stateid = "" if ifs==346
replace stateid = "TON" if ifs==866
replace stateid = "SLO" if ifs==936
replace stateid = "" if ifs==696
replace stateid = "KZK" if ifs==916
replace stateid = "BFO" if ifs==748
replace stateid = "POL" if ifs==964
replace stateid = "" if ifs==326
replace stateid = "" if ifs==887
replace stateid = "CHA" if ifs==628
replace stateid = "ALB" if ifs==914
replace stateid = "" if ifs==823
replace stateid = "LAO" if ifs==544
replace stateid = "" if ifs==815
replace stateid = "" if ifs==376
replace stateid = "ARG" if ifs==213
replace stateid = "MAW" if ifs==676
replace stateid = "" if ifs==373
replace stateid = "UZB" if ifs==927
replace stateid = "BAH" if ifs==419
replace stateid = "SLU" if ifs==362
replace stateid = "DJI" if ifs==611
replace stateid = "ETH" if ifs==644
replace stateid = "MZM" if ifs==688
replace stateid = "PAL" if ifs==565
replace stateid = "CUB" if ifs==928
replace stateid = "MOR" if ifs==686
replace stateid = "SUR" if ifs==366
replace stateid = "BUL" if ifs==918
replace stateid = "" if ifs==377
replace stateid = "SAL" if ifs==253
replace stateid = "CON" if ifs==634
replace stateid = "" if ifs==353
replace stateid = "COL" if ifs==233
replace stateid = "" if ifs==323
replace stateid = "BUI" if ifs==618
replace stateid = "HAI" if ifs==263
replace stateid = "MAA" if ifs==682
replace stateid = "" if ifs==349
replace stateid = "SKN" if ifs==361
replace stateid = "RUS" if ifs==922
replace stateid = "GAM" if ifs==648
replace stateid = "TRI" if ifs==369
replace stateid = "COM" if ifs==632
replace stateid = "" if ifs==318
replace stateid = "ZAM" if ifs==754
replace stateid = "DMA" if ifs==321
replace stateid = "" if ifs==839
replace stateid = "AAB" if ifs==311
replace stateid = "UAE" if ifs==466
replace stateid = "SOL" if ifs==813
replace stateid = "" if ifs==319
replace stateid = "" if ifs==568
replace stateid = "RUM" if ifs==968
replace stateid = "" if ifs==546
replace stateid = "SIN" if ifs==576
replace stateid = "" if ifs==459
replace stateid = "ANG" if ifs==614
replace stateid = "TUN" if ifs==744
replace stateid = "GUY" if ifs==336
replace stateid = "GUI" if ifs==656
replace stateid = "CHN" if ifs==924
replace stateid = "SYR" if ifs==463
replace stateid = "BOT" if ifs==616
replace stateid = "MAA" if ifs==681
replace stateid = "" if ifs==756
replace stateid = "SRI" if ifs==524
replace stateid = "YEM" if ifs==474
replace stateid = "BHU" if ifs==514
replace stateid = "BRU" if ifs==516
replace stateid = "BLZ" if ifs==339
replace stateid = "PAK" if ifs==564
replace stateid = "LEB" if ifs==446
replace stateid = "TAZ" if ifs==738
replace stateid = "TKM" if ifs==925
replace stateid = "DOM" if ifs==243
replace stateid = "" if ifs==856
replace stateid = "COS" if ifs==238
replace stateid = "BHM" if ifs==313
replace stateid = "THI" if ifs==578
replace stateid = "ISR" if ifs==436
replace stateid = "VAN" if ifs==846
replace stateid = "SER" if ifs==965
replace stateid = "SUD" if ifs==732
replace stateid = "GRN" if ifs==328
replace stateid = "MAS" if ifs==684
replace stateid = "GAB" if ifs==646
replace stateid = "SLV" if ifs==961
replace stateid = "" if ifs==333
replace stateid = "UKR" if ifs==926
replace stateid = "MSI" if ifs==867
replace stateid = "CAP" if ifs==624
replace stateid = "IND" if ifs==534
replace stateid = "MNG" if ifs==943
replace stateid = "BOL" if ifs==218
replace stateid = "CYP" if ifs==423
replace stateid = "" if ifs==532
replace stateid = "MYA" if ifs==518
replace stateid = "" if ifs==829
replace stateid = "" if ifs==832
replace stateid = "INS" if ifs==536
replace stateid = "NIC" if ifs==278
replace stateid = "ECU" if ifs==248
replace stateid = "HON" if ifs==268
replace stateid = "GNB" if ifs==654
replace stateid = "" if ifs==312
replace stateid = "TAW" if ifs==528
replace stateid = "MAL" if ifs==548
replace stateid = "" if ifs==329
replace stateid = "" if ifs==816
replace stateid = "QAT" if ifs==453
replace stateid = "JOR" if ifs==439
replace stateid = "ETM" if ifs==579
replace stateid = "EQG" if ifs==642
replace stateid = "UGA" if ifs==746
replace stateid = "SOM" if ifs==726
replace stateid = "LIT" if ifs==946
replace stateid = "SAF" if ifs==199
replace stateid = "FJI" if ifs==819
replace stateid = "PER" if ifs==293
replace stateid = "MLD" if ifs==921
replace stateid = "AZE" if ifs==912
replace stateid = "TUV" if ifs==869
replace stateid = "LIB" if ifs==672
replace stateid = "CAM" if ifs==522
replace stateid = "DRV" if ifs==582
replace stateid = "MAC" if ifs==962
replace stateid = "DRC" if ifs==636
replace stateid = "JAM" if ifs==343
replace stateid = "SVG" if ifs==364
replace stateid = "GRG" if ifs==915
replace stateid = "BAR" if ifs==316
replace stateid = "KEN" if ifs==664
replace stateid = "ARM" if ifs==911
replace stateid = "SEY" if ifs==718
replace stateid = "BNG" if ifs==513
replace stateid = "URU" if ifs==298
replace stateid = "ZIM" if ifs==698
replace stateid = "NAU" if ifs==836
replace stateid = "CRO" if ifs==960
replace stateid = "KYR" if ifs==917
replace stateid = "SIE" if ifs==724
replace stateid = "CDI" if ifs==662
replace stateid = "MON" if ifs==948
replace stateid = "" if ifs==473
replace stateid = "GHA" if ifs==652
replace stateid = "PNG" if ifs==853
replace stateid = "ERI" if ifs==643
replace stateid = "PHI" if ifs==566
replace stateid = "HUN" if ifs==944
replace stateid = "LES" if ifs==666
replace stateid = "FSM" if ifs==868
replace stateid = "CAO" if ifs==622
replace stateid = "CEN" if ifs==626
replace stateid = "BRA" if ifs==223
replace stateid = "" if ifs==363
replace stateid = "NEP" if ifs==558
replace stateid = "IRQ" if ifs==433
replace stateid = "LBR" if ifs==668
replace stateid = "LAT" if ifs==941
replace stateid = "EGY" if ifs==469
replace stateid = "" if ifs==351
replace stateid = "IRN" if ifs==429
replace stateid = "KBI" if ifs==826
replace stateid = "ALG" if ifs==612
replace stateid = "CHL" if ifs==228
replace stateid = "TOG" if ifs==742
replace stateid = "NAM" if ifs==728
replace stateid = "AFG" if ifs==512
replace stateid = "PAN" if ifs==283
replace stateid = "TUR" if ifs==186


sort stateid year

merge stateid year using "evrr_merge.dta"

sort stateid year


***Generate dummy variables beyond evrr_dejure + evrr_defacto***

gen dum_evrr_eldualcit = 0
replace dum_evrr_eldualcit= 1 if evrr_eldualcit==1

gen dum_evrr_eldualcit_permit = 0
replace dum_evrr_eldualcit_permit=1 if evrr_eldualcit_permit==1

gen dum_evrr_elsunset = 0
replace dum_evrr_eldualcit_permit=1 if evrr_eldualcit_permit==1

gen identification = 0
replace identification = 1 if evrr_elid==3
replace identification = 2 if evrr_elid==2
replace identification = 2 if evrr_elid==1
replace identification = 3 if evrr_elid==0
replace identification = . if evrr_elid==.e
replace identification = . if evrr_elid==.

gen dum_evrr_elregres = 0
replace dum_evrr_elregres=1 if evrr_elregres==1

gen dum_evrr_elregres_status = 0
replace dum_evrr_elregres_status=1 if evrr_elregres_status==1

gen dum_evrr_elregres_person = 0
replace dum_evrr_elregres_person=1 if evrr_elregres_person==1

gen dum_evrr_elreghome = 0
replace dum_evrr_elreghome=1 if evrr_elreghome==1

gen dum_evrr_elreghome_person = 0
replace dum_evrr_elreghome_person=1 if evrr_elreghome_person==1

gen dum_evrr_modiplo = 0
replace dum_evrr_modiplo=1 if evrr_modiplo==1

gen dum_evrr_modiplo_broad = 0
replace dum_evrr_modiplo_broad=1 if evrr_modiplo_broad==2

gen dum_evrr_moneighbor = 0
replace dum_evrr_moneighbor=1 if evrr_moneighbor==2

gen dum_evrr_moquotas = 0
replace dum_evrr_moquotas=1 if evrr_moquotas==2

gen dum_evrr_mopost = 0
replace dum_evrr_mopost=1 if evrr_mopost==2

gen dum_evrr_mopost_broad = 0
replace dum_evrr_mopost_broad=1 if evrr_mopost_broad==2

gen dum_evrr_moproxy = 0
replace dum_evrr_moproxy=1 if evrr_moproxy==2

gen dum_evrr_moonline = 0
replace dum_evrr_moonline=1 if evrr_moonline==2

gen dum_evrr_inexec = 0
replace dum_evrr_inexec=1 if evrr_inexec==1

gen dum_evrr_inleg = 0
replace dum_evrr_inleg=1 if evrr_inleg==1

gen dum_evrr_inleg_reps = 0
replace dum_evrr_inleg_reps=1 if evrr_inleg_reps==1

gen dum_evrr_inother = 0
replace dum_evrr_inother=1 if evrr_inother==1

gen dum_evrr_inquotas = 0
replace dum_evrr_inquotas=1 if evrr_inquotas==1



***Run the models***

gen coef=.
gen se=.

global mcontrols dLlnexrate  Llngdppercapita   Lkaopen Llntotal Lpolity

***Appendix Table 10***

*Model 1 - Baseline - This appears Table 1. Model 1. Using remittances as the DV
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf source* [pw=mult] , abs(countryBorn) robust 

*Model 2 - de jure
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure source* [pw=mult] , abs(countryBorn) robust 

*Model 3 - de facto
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_defacto source* [pw=mult] , abs(countryBorn) robust 

*Model 4 - Neighborhood + Disapora Seats
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_moneighbor dum_evrr_inleg_reps  source* [pw=mult] , abs(countryBorn) robust 



***Appendix Table 12 - Micro Supplemental 1***

*Add evrr_dejure
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_defacto
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_defacto source* [pw=mult] , abs(countryBorn) robust 

***Include evrr_dejure + evrr_defacto in the other models

*Add evrr_eldualcit_permit
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_eldualcit source* [pw=mult] , abs(countryBorn) robust 



***Appendix Table 13 - Micro Supplemental 2***

*Add evrr_eldualcit_permit
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_eldualcit_permit source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_elsunset
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_elsunset source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_elid
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto identification source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_elregres
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_elregres source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_elregres_status
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_elregres_status source* [pw=mult] , abs(countryBorn) robust 



***Appendix Table 14 - Micro Supplemental 3***

*Add evrr_elregres_person
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_elregres_person source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_elreghome
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_elreghome source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_elreghome_person
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_elreghome_person source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_modiplo
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_modiplo source* [pw=mult] , abs(countryBorn) robust 



***Appendix Table 15 - Micro Supplemental 4***

*Add evrr_modiplo_broad
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf  evrr_dejure evrr_defacto dum_evrr_modiplo_broad source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_moneighbor
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_moneighbor source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_moquotas
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_moquotas source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_mopost
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_mopost source* [pw=mult] , abs(countryBorn) robust 



***Appendix Table 16 - Micro Supplemental 5***

*Add evrr_mopost_broad
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_mopost_broad source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_moproxy
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_moproxy source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_moonline
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_moonline source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_inexec
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_inexec source* [pw=mult] , abs(countryBorn) robust 



***Appendix Table 17 - Micro Supplemental 6***

*Add evrr_inleg
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_inleg source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_inleg_reps
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_inleg_reps source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_inother
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_inother source* [pw=mult] , abs(countryBorn) robust 

*Add evrr_inquotas
areg remitGross Ldual maxEducUniversity abroadYears abroadYears2 legal  log_income maxWorking  houseSize married spouseOutOf children childrenOutOf parents parentsOutOf evrr_dejure evrr_defacto dum_evrr_inquotas source* [pw=mult] , abs(countryBorn) robust 

